//启动ui模式
"ui";
//-------------------------------------------------------UI函数------------------------------------------------------------------------
//the main ui
function mainUI() {
    ui.layout(
        <drawer id="drawer">
            <vertical>
                <appbar>
                    <toolbar id="toolbar" title="通灵Gyro" bg="{{color}}" clickable="true" >
                        <horizontal layout_gravity="right">
                            <vertical id="startvert" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                                <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                <text id="starttext" bg="?android:attr/selectableItemBackground" text="启动" gravity="center" textSize="10" color="#FFFFFF" />
                            </vertical>
                            <vertical id="scrimg" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                                <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                <text id="boottext" bg="?android:attr/selectableItemBackground" text="图权" gravity="center" textSize="10" color="#FFFFFF" />
                            </vertical>
                            <vertical id="clearbox" clickable="true" bg="?android:attr/selectableItemBackground" margin="0 0 0 0">
                                <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                <text id="boottext" bg="?android:attr/selectableItemBackground" text="清存" gravity="center" textSize="10" color="#FFFFFF" />
                            </vertical>
                        </horizontal>
                    </toolbar>
                    <tabs id="tabs" bg="{{color}}" />
                </appbar>
                <viewpager id="viewpager" bg="{{backg}}" w="*" h="*">
                    <frame>
                        <vertical>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal >
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：停止HUAWEI华为手机所有运行软件" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择蚂蚁森林启动参数(不选软件就不启动，不选功能就登录软件不执行功能,会自动保存上一次的配置，新勾选的功能会变成红色)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="mysl" text='蚂蚁森林' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdmysl" text='不启动蚂蚁森林' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <horizontal margin="0 0 0 0">
                                        <pref-checkbox id="myysbk" text="双倍卡" textColor="#FFFFFF" />
                                        <pref-checkbox id="myynlz" text="能量罩" textColor="#FFFFFF" />
                                        <pref-checkbox id="myhzjs" text="合种浇水" textColor="#FFFFFF" />
                                        <pref-checkbox id="none" text="敬请期待" textColor="#FFFFFF" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择芭芭农场启动参数(不选软件就不启动，不选功能就登录软件不执行功能,会自动保存上一次的配置，新勾选的功能会变成红色)：" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="bbnc" text='芭芭农场' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdbbnc" text='不启动芭芭农场' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <horizontal margin="0 0 0 0">
                                        <pref-checkbox id="sqgs" text="收果实" textColor="#FFFFFF" />
                                        <pref-checkbox id="bbbxrw" text="找宝箱" textColor="#FFFFFF" />
                                        <pref-checkbox id="bbllrw" text="浏览任务" textColor="#FFFFFF" />
                                        <pref-checkbox id="mftq" text="蜜蜂偷取" textColor="#FFFFFF" />
                                    </horizontal>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                    <frame>
                        <vertical>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal >
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal >
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：停止HUAWEI华为手机所有运行软件" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text text="请您选择农行掌银启动参数(不选软件就不启动)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="nhzylxd" text='农行掌银领小豆' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdnhzy" text='不启动农行掌银' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                    <text text="请设置你的农行掌银密码(只用输入一次，之后会存在sqlite数据库中，每次查，默认为lt123456)：" textStyle="bold" margin="0 0 0 0" textColor="#FF0000" layout_gravity="center" />
                                    <horizontal margin="0 0 0 0">
                                        <input id="pd" text="请输入你的密码(点击清除内容)" textColor="#FFFFFF" />
                                        <colored-button id="commit" w="auto" h="auto" text="保存" color="#3CB371" textColor="#FFFFFF" style="Widget.AppCompat.Button.Colored" />
                                    </horizontal>
                                </vertical>
                            </card>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <text textStyle="bold" text="请不要设置手势密码" margin="0 0 0 0" textColor="#FF0000" layout_gravity="center" />
                                    <text text="请您选择云闪付启动参数(不选软件就不启动)：" margin="0 0 0 0" textColor="#FFFFFF" layout_gravity="center" />
                                    <radiogroup id='fbName' orientation="horizontal" margin="0 0 0 0" layout_gravity="center">
                                        <radio id="ysfqd" text='云闪付签到' textColor="#FFFFFF" >
                                        </radio>
                                        <radio id="bqdysf" text='不启动云闪付' textColor="#FFFFFF">
                                        </radio>
                                    </radiogroup>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                    <frame>
                        <vertical>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal>
                                        <img id="startimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_play_circle_filled_white_black_48dp" tint="#FFFFFF" />
                                        <text text="启动：运行当前页选中脚本的选中功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_perm_media_black_48dp" tint="#FFFFFF" />
                                        <text text="图权：申请截图权限，请不要重复启动。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <img id="bootimg" w="25" h="25" padding="0 0 0 0" src="@drawable/ic_delete_forever_black_48dp" tint="#FFFFFF" />
                                        <text text="清存：停止HUAWEI华为手机所有运行软件" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <text text="没有安装auto.js 4.1.0不要启动该功能。" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    <horizontal>
                                        <text text="请联系我给你自动抢红包的脚本，在旧版autojs里面运行" margin="0 0 0 0" textStyle="bold" textColor="#FF0000" layout_gravity="center" />
                                    </horizontal>
                                    <horizontal>
                                        <colored-button id="wxhbstartbtn" text="开始" color="#00DD00" />
                                        <colored-button id="test" text="测试" color="#FF0000" />
                                    </horizontal>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                    <frame>
                        <vertical>
                            <card w="*" h="auto" margin="10 5" clickable="true" foreground="?selectableItemBackground" bg="?android:attr/selectableItemBackground" cardCornerRadius="10dp" cardElevation="10dp" bg="#33000000"  >
                                <vertical>
                                    <horizontal>
                                        <colored-button id="ttjsb" text="头条脚本" color="#FF0000" />
                                    </horizontal>
                                    <horizontal margin="0 0 0 0">
                                        <checkbox id="dyjbyx" text="刷游戏" textColor="#FFFFFF" />
                                        <checkbox id="dysdsp" text="刷视频" textColor="#FFFFFF" />
                                        <checkbox id="dysrw" text="刷任务" textColor="#FFFFFF" />
                                    </horizontal>
                                    <horizontal>
                                    </horizontal>
                                </vertical>
                            </card>
                        </vertical>
                    </frame>
                </viewpager>
            </vertical>
            <vertical layout_gravity="left" bg="#ffffff" w="280">
                <img w="280" h="200" scaleType="fitXY" src="{{bussinesscard}}" />
                <list id="menu">
                    <horizontal bg="?selectableItemBackground" w="*">
                        <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}" />
                        <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
                    </horizontal>
                </list>
            </vertical>
        </drawer>
    );
    //toolbar提示
    ui.toolbar.on("click", () => {
        try {
            win.record.setText("欢迎回到通灵Gyro");
        } catch (err) {
            toast("请打开右侧三个点的提示");
        }
    })
    //头条脚本
    ui.ttjsb.on("click", function() {
        engines.execScriptFile("./res/FuncCollection/超级签到宝.js");
    })
    //清除缓存
    ui.clearbox.on("click", function() {
        toast("该功能只支持recent为横排卡片布局的华为机");
        threads.start(function() {
            recents();
            id("com.huawei.android.launcher:id/clear_all_recents_image_button").findOne().click();
            sleep(2000);
            recents();
            className("android.widget.FrameLayout").desc("通灵Gyro").findOne().click();
        })

    })
    //设置顶部颜色
    ui.statusBarColor(color);
    //创建选项菜单(右上角)
    ui.emitter.on("create_options_menu", menu => {
        menu.add("打开提示");
        menu.add("关闭提示");
        menu.add("关于");
    });
    //监听选项菜单点击
    ui.emitter.on("options_item_selected", (e, item) => {
        switch (item.getTitle()) {
            case "打开提示":
                //定义悬浮窗、画布
                try {
                    win = floaty.rawWindow(
                        <vertical>
                                    <horizontal>
                                        <text text="欢迎使用通灵Gyro" />
                                        <text id="tips" text="未运行任何脚本" marginLeft="10" />
                                    </horizontal>
                                    <text id="record" text="这是一个用爱发电的脚本辅助" />
                                </vertical>
                    );
                    win.setTouchable(false); //悬浮窗不可触摸
                    win.setSize(-1, -1); //-1为铺满屏幕
                } catch (err) {
                    toast("无法打开悬浮窗请重试或者忽略该错误");
                }
                break;
            case "关闭提示":
                win.close();
                break;
            case "关于":
                alert("关于", "目前还有很多不足，我会抽空努力完善的！有问题可以随时联系我微信：This_my_last_gyro");
                break;
        }
        e.consumed = true;
    });
    activity.setSupportActionBar(ui.toolbar);
    //设置滑动页面的标题
    ui.viewpager.setTitles(["阿里软件", "金融软件", "腾讯软件", "签到宝"]);
    //让滑动页面和标签栏联动
    ui.tabs.setupWithViewPager(ui.viewpager);

    //让工具栏左上角可以打开侧拉菜单
    ui.toolbar.setupWithDrawer(ui.drawer);
    //set the data source of list
    ui.menu.setDataSource([{
            title: "检测安卓版本",
            icon: "@drawable/ic_android_black_48dp"
        },
        {
            title: "开启无障碍服务",
            icon: "@drawable/ic_settings_black_48dp"
        },
        {
            title: "主题与皮肤",
            icon: "@drawable/ic_favorite_black_48dp"
        },
        {
            title: "检测手机分辨率",
            icon: "@drawable/ic_stay_current_landscape_black_48dp"
        },
        {
            title: "检测手机品牌",
            icon: "@drawable/ic_stay_current_portrait_black_48dp"
        },
        {
            title: "我的b站主页（欢迎一起学习）",
            icon: "@drawable/ic_format_bold_black_48dp"
        },
        {
            title: "查看日志及参数",
            icon: "@drawable/ic_build_black_48dp"
        },
        {
            title: "隐藏日志及参数",
            icon: "@drawable/ic_backspace_black_48dp"
        },
        {
            title: "退出",
            icon: "@drawable/ic_exit_to_app_black_48dp"
        }
    ]);
    //set the different case invoking different function
    ui.menu.on("item_click", item => {
        switch (item.title) {
            case "退出":
                ui.finish();
                break;
            case "检测安卓版本":
                toastLog("安卓" + device.release);
                break;
            case "检测手机分辨率":
                toastLog(device.width + "*" + device.height);
                break;
            case "检测手机品牌":
                toastLog(device.brand);
                break;
            case "我的b站主页（欢迎一起学习）":
                biliUI();
                break;
            case "主题与皮肤":
                themeUI();
                break;
            case "查看日志及参数":
                console.clear();
                console.log("蚂蚁森林：");
                //logging the maiyisenlin setting that was selected from db
                console.log(db.rawQuery("SELECT * FROM MYSL", null).all()[0]);
                console.log("农行掌银：");
                //logging the ABC mobile bank setting that was selected from db
                console.log(db.rawQuery("SELECT * FROM ABCZY", null).all()[0]);
                console.log("抖音游戏:");
                console.log(douyin_storage.get("game"));
                console.log("抖音视频:");
                console.log(douyin_storage.get("video"));
                console.log("抖音任务:");
                console.log(douyin_storage.get("task"));
                console.show();
                break;
            case "隐藏日志及参数":
                console.hide();
                break;
            case "开启无障碍服务":
                app.startActivity({
                    action: "android.settings.ACCESSIBILITY_SETTINGS"
                });
                toastLog("请给我无障碍服务权限");
                break;
        }
    })

    //功能参数选择消息提示气泡------------------------------------------------------------------------------------
    ui.mysl.on("check", () => {
        if (className("android.widget.RadioButton").text("蚂蚁森林").findOnce().checked()) {
            ui.mysl.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了将要启动蚂蚁森林脚本");
        } else {
            ui.mysl.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了蚂蚁森林脚本");
        }
    })
    //农行掌银领小豆
    ui.nhzylxd.on("check", () => {
        if (className("android.widget.RadioButton").text("农行掌银领小豆").findOnce().checked()) {
            ui.nhzylxd.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了将要启动农行掌银领小豆脚本");
        } else {
            ui.nhzylxd.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了农行掌银领小豆脚本");
        }
    })
    //蚂蚁森林
    ui.myhzjs.on("check", () => {
        if (className("android.widget.CheckBox").text("合种浇水").findOnce().checked()) {
            ui.myhzjs.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了合种浇水参数");
            db.update("MYSL", {
                watering: true
            }, "ID = ?", [1])
        } else {
            ui.myhzjs.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了合种浇水参数");
            db.update("MYSL", {
                watering: false
            }, "ID = ?", [1])
        }
    });
    ui.myysbk.on("check", () => {
        if (className("android.widget.CheckBox").text("双倍卡").findOnce().checked()) {
            ui.myysbk.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了双倍卡参数");
            db.update("MYSL", {
                doublecard: true
            }, "ID = ?", [1])
        } else {
            ui.myysbk.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了双倍卡参数");
            db.update("MYSL", {
                doublecard: false
            }, "ID = ?", [1])
        }
    });
    ui.myynlz.on("check", () => {
        if (className("android.widget.CheckBox").text("能量罩").findOnce().checked()) {
            ui.myynlz.setTextColor(colors.parseColor("#FF0000"));
            toastLog("你选择了能量罩参数");
            db.update("MYSL", {
                shield: true
            }, "ID = ?", [1])
        } else {
            ui.myynlz.setTextColor(colors.parseColor("#FFFFFF"));
            toastLog("你取消了能量罩参数");
            db.update("MYSL", {
                shield: false
            }, "ID = ?", [1])
        }
    })
    //农行小豆
    ui.pd.on("click", function() {
        ui.pd.setText("")
    });
    ui.commit.on("click", function() {
        db.update("ABCZY", {
            password: className("android.widget.EditText").findOnce().text()
        }, "id=?", [1]);
        toastLog("修改成功")
    });
    //启动函数
    ui.startvert.on("click", function() {
        if (className("android.widget.TextView").text("启动").exists()) {
            ui.startimg.setSource("@drawable/ic_pause_circle_filled_black_48dp");
            ui.starttext.setText("暂停");
            toastLog("运行当前选择的脚本");
            if (text("阿里软件").findOnce().selected() && className("android.widget.RadioButton").text("芭芭农场").findOnce().checked()) {
                engines.execScriptFile("./res/FuncCollection/芭芭农场领阳光.js");
            } else if (text("阿里软件").findOnce().selected() && className("android.widget.RadioButton").text("蚂蚁森林").findOnce().checked()) {
                engines.execScriptFile("./res/FuncCollection/新版蚂蚁森林.js")
            } else if (text("金融软件").findOnce().selected() && className("android.widget.RadioButton").text("农行掌银领小豆").findOnce().checked()) {
                toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
                engines.execScriptFile("./res/FuncCollection/农行小豆.js");
            } else if (text("金融软件").findOnce().selected() && className("android.widget.RadioButton").text("云闪付签到").findOnce().checked()) {
                toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
                engines.execScriptFile("./res/FuncCollection/云闪付签到.js");
            }
        } else if (className("android.widget.TextView").text("暂停").exists()) {
            ui.startimg.setSource("@drawable/ic_play_circle_filled_white_black_48dp");
            ui.starttext.setText("启动");
            threads.shutDownAll();
            toastLog("停止所有运行的脚本");
        }
    });
    ui.scrimg.on("click", function() {
        try {
            threads.start(function() {
                text("立即开始").findOne().click();
            });
            threads.start(function() {
                images.requestScreenCapture(); //向系统省去截图权限
            })
            let err = new Error
            err.name = "截图权限已开启"
            err.message = "你已经打开截图权限请不要重复提交"
            throw err
        } catch (err) {
            toastLog(err, err.name, err.message);
        }
    });
    ui.wxhbstartbtn.on("click", function() {
        toastLog("Link start!( ˃̶̤́ ꒳ ˂̶̤̀ )")
        app.launchApp("Auto.js")
    })
}
//the webview ui about bilibili
function biliUI() {
    ui.layout(
        <frame>
            <horizontal bg="{{color}}">
                <colored-button id="backbtn" color="{{color}}" text="返回Gyro" />
            </horizontal>
            <horizontal>
                <webview id="webview" margin="0 60 0 0" />
            </horizontal>
        </frame>
    )
    ui.webview.loadUrl("https://m.bilibili.com/space/166269644");
    ui.backbtn.on("click", () => mainUI())
}
//the theme ui about settings
function themeUI() {
    //皮肤
    skinCollection = db.rawQuery('SELECT * FROM SKIN', null).all();
    exechead = "ui.layout(\
    <scroll bg='{{backg}}'>\
        <vertical bg='#707070' padding='16'>\
            <text text='皮肤：' textColor='black' textSize='16sp' marginTop='16' />";
    exectail = "        </vertical>\
 </scroll>\
);";
    execbody = "";
    execuilsnr = "";
    for (n = 0; n < skinCollection.length; n++) {
        execuilsnr += "ui." + skinCollection[n]['skinname'] + ".on('click',()=>{\
        let db = sqlite.open('./data.db', {\
                    version: 1});\
               db.update('THEMESETTINGS', {\
            skinpath:'" + skinCollection[n]['skinpath'] + "'}, 'id = ?', ['1']);\
            toast('" + skinCollection[n]['skinname'] + "皮肤设置成功');\
            db.close();\
            });";
        if (n % 4 == 0) {
            execbody += "            <horizontal>\
                <vertical id='" + skinCollection[n]['skinname'] + "' w='80' h='120' clickable='true' bg='?android:attr/selectableItemBackground' alpha='1' >\
                    <text text='" + skinCollection[n]['skinname'] + "' textColor='black' textSize='16sp' marginTop='16' gravity='center' />\
                    <img src='" + skinCollection[n]['skinpath'] + "'\
                    borderWidth='2dp' borderColor='#202020' />\
                </vertical>";
        }
        if ((n + 1) % 4 == 0) {
            execbody += "                <vertical id='" + skinCollection[n]['skinname'] + "' w='80' h='120' clickable='true' bg='?android:attr/selectableItemBackground' alpha='1' >\
                    <text text='" + skinCollection[n]['skinname'] + "' textColor='black' textSize='16sp' marginTop='16' gravity='center' />\
                    <img src='" + skinCollection[n]['skinpath'] + "'\
                    borderWidth='2dp' borderColor='#202020' />\
                </vertical>\
                 </horizontal>";
        } else if (n + 1 == skinCollection.length) {
            execbody += "</horizontal>";
        }
        if (n % 4 > 0 && n % 4 < 3) {
            execbody += "                <vertical id='" + skinCollection[n]['skinname'] + "' w='80' h='120' clickable='true' bg='?android:attr/selectableItemBackground' alpha='1' >\
                    <text text='" + skinCollection[n]['skinname'] + "' textColor='black' textSize='16sp' marginTop='16' gravity='center' />\
                    <img src='" + skinCollection[n]['skinpath'] + "'\
                    borderWidth='2dp' borderColor='#202020' />\
                </vertical>";
        }
    }
    //名片卡
    cardCollection = db.rawQuery('SELECT * FROM bussinesscard', null).all();
    execcardhead = "                <text text='名片卡：' textColor='black' textSize='16sp' marginTop='16' />\
                <horizontal>"
    execcardbody = ""
    execcardtail = "</horizontal>"
    for (n = 0; n < cardCollection.length; n++) {
        execuilsnr += "ui." + cardCollection[n]['bussinesscardname'] + ".on('click', () => {\
        db.update('THEMESETTINGS', {\
            bussinesscardpath: '" + cardCollection[n]['bussinesscardpath'] + "'\
        }, 'id = ?', ['1']);\
        toast('设置成功!')\
    });"
        execcardbody += "                    <vertical id='" + cardCollection[n]['bussinesscardname'] + "' w='80' h='80' clickable='true' bg='?android:attr/selectableItemBackground'>\
                        <text text='" + cardCollection[n]['bussinesscardname'] + "' textColor='black' textSize='16sp' marginTop='16' gravity='center' />\
                        <img src='" + cardCollection[n]['bussinesscardpath'] + "' circle='true'\
                        borderWidth='2dp' borderColor='#202020' />\
                    </vertical>"
    }
    //颜色盘
    colorname = ["纯黑", "骚粉", "原谅", "真爱", "基佬", "残阳", "樱花", "橙子", "月光", "淡然", "咖啡", "雨后"]
    colorcode = ["#000000", "#FFB6C1", "#3CB371", "#00BFFF", "#9400D3", "#FF0000", "#feeeed", "#ff6600", "#ffff00", "#ccffff", "#cc6600", "#c0ffee"]
    colorbody = "<horizontal>"
    for (n in colorname) {
        execuilsnr += "ui." + colorname[n] + ".on('click', () => {\
        color_storage.put('color','" + colorcode[n] + "');\
        toast('颜色修改成功')\
    });"
        if (n % 6 == 0 && n != 0 && n != colorname.length - 1) {
            colorbody += "            </horizontal>\
                                <horizontal>\
                                 <vertical id='" + colorname[n] + "' w='50' h='90' clickable='true' bg='?android:attr/selectableItemBackground'>\
                                        <text text='" + colorname[n] + "' textColor='#FFFFFF' textSize='16sp' marginTop='16' gravity='center' />\
                                        <text w='50' h='50' bg='" + colorcode[n] + "' />\
                                    </vertical>"
        } else if (n == colorname.length - 1) {
            colorbody += "          <vertical id='" + colorname[n] + "' w='50' h='90' clickable='true' bg='?android:attr/selectableItemBackground'>\
                                        <text text='" + colorname[n] + "' textColor='#FFFFFF' textSize='16sp' marginTop='16' gravity='center' />\
                                        <text w='50' h='50' bg='" + colorcode[n] + "' />\
                                    </vertical>\
                                   </horizontal>\
                                 <input id='selfcolor' textStyle='bold' text='请输入自定义16进制颜色码(长按清除文本)' textColor='#FFFFFF' />\
                                <horizontal gravity='center'>\
                                    <button text='提交颜色码' id='commitcolor' backgroundTint='#00000000' textColor='#FFFFFF' />\
                                    <button text='查看颜色码' id='viewcolor' backgroundTint='#00000000' textColor='#FFFFFF' />\
                                    <button id='backbtn' text='返回Gyro' backgroundTint='#00000000' />\
                                </horizontal>"
        } else {
            colorbody += "                 <vertical id='" + colorname[n] + "' w='50' h='90' clickable='true' bg='?android:attr/selectableItemBackground'>\
                                        <text text='" + colorname[n] + "' textColor='#FFFFFF' textSize='16sp' marginTop='16' gravity='center' />\
                                        <text w='50' h='50' bg='" + colorcode[n] + "' />\
                                    </vertical>"
        }
    }
    execuilsnr += "ui.selfcolor.on('long_click', () => {\
        ui.selfcolor.setText('#');\
    });\
    ui.commitcolor.on('click', () => {\
        color_storage.put('color', ui.selfcolor.getText().toString());\
    });\
    ui.viewcolor.on('click', () => {\
        i = app.intent({\
            action: 'VIEW',\
            data: 'https://www.cnblogs.com/planetwithpig/p/11663209.html'\
        });\
        app.startActivity(i);\
    });\
    ui.backbtn.on('click', () => {\
        backg = db.rawQuery('SELECT * FROM THEMESETTINGS where id = ?', ['1']).single()['skinpath'];\
        color = color_storage.get('color');\
        bussinesscard = db.rawQuery('SELECT * FROM THEMESETTINGS where id = ?', ['1']).single()['bussinesscardpath'];\
        mainUI()\
    })"
    color_storage = storages.create("color");
    execcard = execcardhead + execcardbody + execcardtail;
    execSkinCode = exechead + execbody + execcard + colorbody + exectail + execuilsnr;
    eval(execSkinCode);
}
//-------------------------------------------------------主函数部分--------------------------------------------------------------------
//调用js文件
var PrefCheckBox = require('./uisetting.js');
var Func = require('./func.js')
//打开数据库
let db = sqlite.open("./data.db", {
    version: 1
});
//全局变量
backg = db.rawQuery("SELECT * FROM THEMESETTINGS where id = ?", ["1"]).single()["skinpath"];
bussinesscard = db.rawQuery("SELECT * FROM THEMESETTINGS where id = ?", ["1"]).single()["bussinesscardpath"];
color_storage = storages.create("color");
color = color_storage.get("color");
threads.start(function() {
    auto.waitFor(); //判断是否启动无障碍服务
    text("立即开始").findOne().click();
});
threads.start(function() {
    images.requestScreenCapture(); //向系统省去截图权限
})
//调用主界面函数
mainUI()